Skip to content

Fix uv_close race condition#658

Open
tbachman wants to merge 1 commit intomasterfrom
fix-close
Open

Fix uv_close race condition#658
tbachman wants to merge 1 commit intomasterfrom
fix-close

Conversation

@tbachman
Copy link
Copy Markdown
Contributor

When the PlatformConfig MO is deleted, the agent disconnects the existing peers, and adds the configured ones. When disconnecting the existing peers, it makes a call to uv_close on the libuv handle for the TCP socket. This call is made in a different context than the libuv context that's processing events. This can lead to a race condition, where the libuv handle for that socket is marked as closing, but the libuv thread invokes the pending callbacks for this handle, resulting in the following assert:

uv__stream_io: Assertion `!(stream->flags & UV_HANDLE_CLOSING)' failed.

To avoid this, the call to uv_close needs to be deferred to the libuv processing context. This patch adds a queue to make deferred close calls, which are handled in the libuv threads async callback.

When the PlatformConfig MO is deleted, the agent disconnects the
existing peers, and adds the configured ones. When disconnecting
the existing peers, it makes a call to uv_close on the libuv handle
for the TCP socket. This call is made in a different context than
the libuv context that's processing events. This can lead to a race
condition, where the libuv handle for that socket is marked as
closing, but the libuv thread invokes the pending callbacks for
this handle, resulting in the following assert:

  uv__stream_io: Assertion `!(stream->flags & UV_HANDLE_CLOSING)' failed.

To avoid this, the call to uv_close needs to be deferred to the
libuv processing context. This patch adds a queue to make deferred
close calls, which are handled in the libuv threads async callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants